package com.qcnh.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcnh.entity.Payment;
import com.qcnh.mapper.PaymentMapper;
import com.qcnh.service.PaymentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import unil.Result;

import java.util.List;

/**
 * <p>
 * 支付记录表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2024-12-05
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {
    @Autowired
    private  PaymentMapper paymentMapper;

    //分页查询订单并支持根据用户id进行模糊查询
    @Override
    public IPage<Payment> selectAllPayments(Integer current, Integer size, String keyWord) {
        Page<Payment> page = new Page<>(current,size);//创建分页对象
        QueryWrapper<Payment> wrapper = new QueryWrapper<>();//创建查询对象
        if(StringUtils.isNotBlank(keyWord))//判空处理并模糊查询
            wrapper.like("user_id",keyWord);
        return paymentMapper.selectPage(page, wrapper);
    }

    //添加订单
    @Override
    public Boolean addPayment(Payment payment) {
        return paymentMapper.insert(payment)>0?true:false;
    }

    //根据订单id集合批量删除订单
    @Override
    public Boolean delPaymentsByIdList(List<Integer> paymentIds) {
        return paymentMapper.deleteBatchIds(paymentIds)>0?true:false;
    }

    //更新订单信息
    @Override
    public Boolean updatePayment(Payment payment) {
        return paymentMapper.updateById(payment)>0?true:false;
    }
}
